﻿using OperationPlugins.Handlers;

namespace OperationPlugins
{
    internal sealed class InternalEnvelope<TContent>
    {
        internal TContent Content { get; private set; }

        private InternalEnvelope(TContent content)
        {
            Content = content;
        }

        internal static void Dispatch(TContent content, IOperationContextFactory contextFactory)
        {
            var envelope = new InternalEnvelope<TContent>(content);

            Handlers.Handler.Invoke(envelope, Operations.Internal, Branches.Internal, contextFactory);
        }

        [InternalOperationFilter]
        [InternalBranchFilter]
        [DefaultPriority]
        internal abstract class Handler : AbstractHandler
        {
            protected new TContent Value 
            { 
                get { return ((InternalEnvelope<TContent>) base.Value).Content; }
            }
        }
    }
}
